<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	include ROOTPATH .'include'. DS .'isMyQuery.php';
	include(ROOTPATH .'include'. DS .'checkUserLogin.php');
	$powder_min = 5 ;
	include(ROOTPATH .'include'. DS .'checkPowder.php');	
	
	include_once(ROOTPATH .'class'. DS .'task.class.php');
	
	include_once(ROOTPATH .'class'. DS .'mail.calss.php');
	
	$task_id			= getId('task_id');
	$userEmail			= getQuery('userEmail');
	$description		= getQuery('description');
	$timeEnd			= getQuery('timeEnd');
	$selectionArea		= getQuery('selectionArea');
	$inviteLang			= getQuery('inviteLang');
	switch($do){
		case 'invite'	: invite($task_id,$userEmail,$description,$timeEnd,$selectionArea);
		break ;
	}



function invite($task_id,$userEmail,$description,$timeEnd,$selectionArea ){	
	global $dbs , $user ,$encrypt;
	$split_string = INVITE_SPLIT_STRING ? INVITE_SPLIT_STRING : '|-_-|' ;
	$task = new task();
	
	// 不信任客户端,再次检测。
	$sql = 'SELECT * FROM `'.DB_PRE.'task` WHERE `id` = '.$task_id ;
	$lists = $dbs -> select($sql);

	$task -> checkOwner($lists[0]['user_id']);
	
	$userEmail = explode('|',$userEmail);
	if( count($userEmail) == 0  )
		exit( '<font class="error">您还没有添加评阅人</font>');
	if( $timeEnd == '' )
		exit( '<font class="error">请填写评审结束时间</font>');
	$inviteUrl = '';
	
//	$email = new email();
//	$email -> send($to,$name,$title,$body);
	
	$inviteUrls = '';
	foreach($userEmail as $email){
		if(!isEmail($email)) continue;
		$inviteUrl = $task_id . $split_string . $email . $split_string . $timeEnd . $split_string . $selectionArea ;
		$inviteUrl = $encrypt -> code($inviteUrl);
		$inviteUrls .= '<br /><br />'.  $email .':<br />'. $inviteUrl ;
		$array['invite']			= $email ;
		$array['task_id'] 			= $task_id;		
		$array['user_id'] 			= $user -> id();
		$array['timeEnd'] 			= $timeEnd ;
		$array['lang'] 				= getQuery('inviteLang');		
		$array['selectionArea'] 	= $selectionArea;
		$array['created']			= date('Y-m-d H:i:s',time());
		$array['ip'] 				= ip() ;		
		$dbs -> insert( DB_PRE.'task_invite' ,$array);
	}
	echo '<font class="ok">成功邀请,已给对方发送邀请邮件.'. WEB_ROOT_PATH.'?option=taskAssess&query=' . $inviteUrl.'&amp;lang='.getQuery('inviteLang').'</font>';
}
?>